<template>
  <tm-app :transparent="true">
    <view class="custom-login">
      <view class="custom-login-top">
        <img
          class="custom-login-top-logo"
          src="../../static/tabbar-ico/logo.png"
        />
        <view class="custom-login-top-title">浙里资产</view>
      </view>
    </view>
  </tm-app>
</template>

<script lang="ts" setup>
import { onLoad, onShow } from '@dcloudio/uni-app'
import Common from '../home/common/common'
// #ifdef H5 || MP-ALIPAY
import * as ddEnv from 'dingtalk-jsapi'
import { singleSignOn } from '@/utils/ddlogin'
// #endif
import orgCtrl from '@/ts/controller'
import { locallogin } from '@/utils/locallogin'

onLoad(() => {
  Common.clear()
})

onShow(async () => {
  const token = uni.getStorageSync('accessToken')
  /** 每次小程序从后台进入前台时，判断token是否存在 */

  const loginFun = async () => {
    if (!token) {
      locallogin()
    } else {
      await orgCtrl.auth.noSignIn(token)
      uni.reLaunch({
        url: '/pages/home/home'
      })
    }
  }

  // #ifdef MP-WEIXIN
  loginFun()
  // #endif

  // #ifdef H5 || MP-ALIPAY
  if (ddEnv.env.platform === 'notInDingTalk') {
    loginFun()
  } else {
    if (!token) {
      singleSignOn()
    } else {
      await orgCtrl.auth.noSignIn(token)
      uni.reLaunch({
        url: '/pages/home/home'
      })
    }
  }
  // #endif
})
</script>

<style lang="scss" scoped>
.custom-login {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(#bbdefc, 10%, #fff);
  background-size: 100% 100%;
  box-sizing: border-box;
  padding-left: 32rpx;
  padding-right: 32rpx;
  .custom-login-top {
    margin-top: 30%;
    margin-bottom: 150rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    .custom-login-top-logo {
      width: 82rpx;
      height: 82rpx;
    }
    .custom-login-top-title {
      font-size: 52rpx;
      font-weight: 500;
      margin-left: 10rpx;
    }
  }
  .custom-login-tabs {
    width: 100%;
    margin-bottom: 40rpx;
  }
  .custom-login-input {
    width: 100%;
    margin-top: 32rpx;
    margin-bottom: 64rpx;
    .custom-use-svg {
      width: 40rpx;
      height: 40rpx;
      margin-right: 16rpx;
    }
    .zhanghao {
      background-color: red;
    }
  }
  .custom-login-button {
    width: 100%;
    height: 100rpx;
    margin-bottom: 32rpx;
  }
}
</style>
